<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="java.util.*, linuxbox.filelib.logic.*,linuxbox.admin.logic.*" %>
<%@ taglib uri="/linuxbox/common.tld" prefix="common" %>

<jsp:include page="/en/jsp/header.jsp" flush="false"/>

<%
  SearchEntry criteria = (SearchEntry)session.getAttribute("filelib.SEARCHENTRY");

  String folderContentAction = BoxStatic.servletDir+"FolderContentAction";
  String folderSearchAction = BoxStatic.servletDir+"FileLibSearchAction?SubmitSort=search&";

  FileLibHome home = FileLibHome.getInstance();
  UserManager um = UserManager.getInstance();
%>


<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td>
	    &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
	    <b><%=boxName%> - File Library&nbsp; - Search</b>
    </td>
    <td align=right>
      <a href="<%=BoxStatic.servletDir%>BoxFileLibSettingsAction?SubmitEdit=edit">
        Settings
      </a>
    </td>
  </tr>
</table>
<hr width=\"100%\" color=#E06000 align=left>

<form name="searchForm" method="post" action="<%=BoxStatic.servletDir%>FileLibSearchAction" >
  <table width= "100%" border=1 cellspacing=0 cellpadding=1>
    <%
      Iterator errIt = criteria.validationMsgs.iterator();
      if (errIt != null && errIt.hasNext())
      {
        while (errIt.hasNext())
        {
          String errMsg = (String)errIt.next();
          out.print("<tr bgcolor=\"#f4f5e1\"> <td nowrap align=\"left\"><b><font color=#ff0000>");
          out.print(errMsg);
          out.println("</font></b></td> </tr>");
        }
      }
		%>
    <TR bgcolor="#7EC1F3">
      <TD colSpan=2> <B>Search Folder/Files:</B>
      </TD>
    </TR>
    <tr>
      <td>
            <B>Search words:</B>
            <INPUT type=text name="SEARCH_TEXT" MAXLENGTH=80 SIZE=30 value=<%=criteria.searchText%> >
            <input type="submit" name="SubmitSearch" value="Search">
            <br>
            <input type=checkbox name="SEARCH_BY_NAME" value="1"
            <%
              if (criteria.searchName)
                out.print(" checked ");
            %>> Look in Name
            <input type=checkbox name="SEARCH_BY_FILENAME" value="1"
            <%
              if (criteria.searchFilename)
                out.print(" checked ");
            %>> Look in Filename
            <input type=checkbox name="SEARCH_BY_FOLDERNAME" value="1"
            <%
              if (criteria.searchFoldername)
                out.print(" checked ");
            %>> Look in Folder name
      </td>
    </tr>

    <tr>
      <td>
            <B><input type=checkbox name="SEARCH_BY_TIME" value="1"
            <%
              if (criteria.searchByTime)
                out.print(" checked ");
            %>>And is modified between </B>
            <select name="FROM_MONTH" size="1">
              <common:MonthList  selected="<%=criteria.modifiedFrom.get(Calendar.MONTH)%>" allownull="false" />
            </select>
            <select name="FROM_DAY" size="1">
              <common:DayList selected="<%=criteria.modifiedFrom.get(Calendar.DAY_OF_MONTH)%>" allownull="false" />
            </select>
            <select name="FROM_YEAR" size="1">
              <common:YearList selected="<%=criteria.modifiedFrom.get(Calendar.YEAR)%>" allownull="false" />
            </select>
            and
            <select name="TO_MONTH" size="1">
              <common:MonthList  selected="<%=criteria.modifiedTo.get(Calendar.MONTH)%>" allownull="false" />
            </select>
            <select name="TO_DAY" size="1">
              <common:DayList selected="<%=criteria.modifiedTo.get(Calendar.DAY_OF_MONTH)%>" allownull="false" />
            </select>
            <select name="TO_YEAR" size="1">
              <common:YearList selected="<%=criteria.modifiedTo.get(Calendar.YEAR)%>" allownull="false" />
            </select>
      </td>
    </tr>
    <tr>
      <td>
            <B><input type=checkbox name="SEARCH_BY_SIZE" value="1"
            <%
              if (criteria.searchBySize)
                out.print(" checked ");
            %>>And Size is </B>
            <select name="SEARCH_SIZE_GREATER" size="1" >
              <option value="0" <% if (criteria.isSizeGreater) out.print("selected"); %>>more than</option>
              <option value="1" <% if (!criteria.isSizeGreater) out.print("selected"); %>>less than</option>
            </select>
            <input SIZE=6 name="SEARCH_SIZE" value="<%=criteria.size%>">
            <select name="SEARCH_SIZE_UNIT" size="1" >
              <option value="<%=SearchEntry.SIZEUNIT_BYTES%>" <% if (criteria.sizeUnit==SearchEntry.SIZEUNIT_BYTES) out.print("selected"); %>>Bytes</option>
              <option value="<%=SearchEntry.SIZEUNIT_KBYTES%>" <% if (criteria.sizeUnit==SearchEntry.SIZEUNIT_KBYTES) out.print("selected"); %>>KBytes</option>
              <option value="<%=SearchEntry.SIZEUNIT_MBYTES%>" <% if (criteria.sizeUnit==SearchEntry.SIZEUNIT_MBYTES) out.print("selected"); %>>MBytes</option>
            </select>
      </td>
    </tr>
    <tr>
      <td>
<%
    Iterator it = criteria.resultIt;
    if (it == null || !it.hasNext())
    {
      if (criteria.searchText != null && criteria.searchText.length()>0)
      {
        out.println("<b><h2>No results found!</h2></b>");
      }
    }
    else
    {
      String[] headers = {"Folder", "Name", "Filename", "Size", "Modified", "Owner"};
      String[] sortby = {"parent", "name", "filename", "size", "lastmodifiedtime", "ownerid"};
%>
        <table border="1"  cellpadding="0" cellspacing="0">
         <tr>
          <td>
            <h3>Search result:</h3>
          </td>
        </tr>
        <TR bgColor=#cccccc>
          <common:ListHeader headers="<%=headers%>" sortby="<%=sortby%>" curSortBy="<%=criteria.sortBy%>" sortAsc="<%=criteria.sortAsc%>" action="<%=folderSearchAction%>" />
        </TR>
        <common:Iteration name="entry" type="FileLibEntry" group="<%=it%>">
<%
        if (entry.getIsfolder())
        {
%>
        <TR>
          <td>
            <A href="<%=BoxStatic.servletDir%>FolderContentAction?FOLDERID=<%=entry.getParent()%>"><IMG src="<%=BoxStatic.imageDir%>folder.gif" border=0>
              <%=home.getPathString(entry.getParent())%>
            </A><BR>
          </td>
          <TD style="BORDER-RIGHT: #cccccc 0px solid; BORDER-TOP: #cccccc 0px solid; BORDER-LEFT: #cccccc 0px solid; BORDER-BOTTOM: #cccccc 1px solid" bgColor=#ffffff>
            <A title="" href="<%=BoxStatic.servletDir%>FolderContentAction?FOLDERID=<%=entry.getID()%>"><IMG src="<%=BoxStatic.imageDir%>folder.gif" border=0><%=entry.getName()%></A><BR></TD>
          <TD>&nbsp;</TD>
          <TD>&nbsp;</TD>
          <TD><%=entry.getLastmodifiedtimeString()%>&nbsp;</TD>
          <TD><%=um.getUserDisplayName(entry.getOwnerid(), um.USERNAME_FORMAT_ALL)%>&nbsp;</TD>
        </TR>
<%
        }
        else
        {
%>
        <TR bgColor=#ffffff>
          <td>
            <A href="<%=BoxStatic.servletDir%>FolderContentAction?FOLDERID=<%=entry.getParent()%>"><IMG src="<%=BoxStatic.imageDir%>folder.gif" border=0>
              <%=home.getPathString(entry.getParent())%>
            </A><BR>
          </td>
          <TD style="BORDER-RIGHT: #cccccc 0px solid; BORDER-TOP: #cccccc 0px solid; BORDER-LEFT: #cccccc 0px solid; BORDER-BOTTOM: #cccccc 1px solid">
            <A href="<%=BoxStatic.servletDir%>EditFileAction?SubmitView=view&ID=<%=entry.getID()%>">
              <IMG hspace=1 src="<%=BoxStatic.imageDir%>pubfile.gif" border=0><%=entry.getName()%>
            </A>
          </TD>
          <TD style="BORDER-RIGHT: #cccccc 0px solid; BORDER-TOP: #cccccc 0px solid; BORDER-LEFT: #cccccc 0px solid; BORDER-BOTTOM: #cccccc 1px solid">
            <A href="<%=BoxStatic.servletDir%>DownloadFileAction?ID=<%=entry.getID()%>" >
              <%=entry.getFilename()%>
          </TD>
          <TD style="BORDER-RIGHT: #cccccc 0px solid; BORDER-TOP: #cccccc 0px solid; BORDER-LEFT: #cccccc 0px solid; BORDER-BOTTOM: #cccccc 1px solid" noWrap align=right>
              <%=entry.getSizeString()%>&nbsp;
          </TD>
          <TD><%=entry.getLastmodifiedtimeString()%>&nbsp;</TD>
          <TD><%=um.getUserDisplayName(entry.getOwnerid(), um.USERNAME_FORMAT_ALL)%>&nbsp;</TD>
        </TR>
<%
        }
%>
        </common:Iteration>
        </table>
<%
    }
%>
      </td>
    </tr>
  </table>
</form>

  <hr width=\"100%\" color=#E06000 align=left>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
